package com.rainbow.commons.mybatis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @author Rainbow on 2018/7/3
 */
public class SuperController<S extends ISuperService<T>, T extends SuperEntity> {


    @SuppressWarnings("MemberVisibilityCanBePrivate")
    @Autowired
    protected S baseService;

    @GetMapping("/{id}")
    public T get(@PathVariable("id") String id) {
        return baseService.selectById(id);
    }

    @PutMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void update(@PathVariable String id, @RequestBody T t) {
        baseService.updateById(t);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void create(@RequestBody T t) {
        baseService.insert(t);
    }

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void delete(@PathVariable String id) {
        baseService.deleteById(id);
    }
}
